/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddTextePnl.java
 *
 * Created on 20 nov. 2011, 15:00:18
 */
package com.sma.renamefilewindows.ihm.panel;

import com.sma.renamefilewindows.ihm.FrameContainer;
import com.sma.renamefilewindows.utils.StringUtils;
import com.sma.renamefilewindows.utils.classe.Couple;
import com.sma.renamefilewindows.utils.classe.PositionUtils;
import java.io.IOException;
import javax.swing.JOptionPane;

/**
 *
 * @author SMA
 */
public class AddTextePnl extends javax.swing.JPanel implements UpdaterListeFichier {

    private FrameContainer parent = null;

    /** Creates new form AddTextePnl */
    public AddTextePnl(FrameContainer _parent) {
        this.parent = _parent;
        __initComponents();
    }

    private void __initComponents() {
        initComponents();
        this.texte.setText("");
        PositionUtils.initComboListPosition(this.positionToAddTexte);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        texte = new javax.swing.JTextField();
        positionToAddTexte = new javax.swing.JComboBox();

        jLabel1.setText("Ajouter :");

        texte.setText("jTextField1");
        texte.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                texteKeyReleased(evt);
            }
        });

        positionToAddTexte.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        positionToAddTexte.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                positionToAddTexteItemStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(texte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(positionToAddTexte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(64, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(texte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(positionToAddTexte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void texteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_texteKeyReleased
    actionPerformed();
}//GEN-LAST:event_texteKeyReleased

private void positionToAddTexteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_positionToAddTexteItemStateChanged
    if (this.positionToAddTexte.getItemCount() != 0) {
        actionPerformed();
    }
}//GEN-LAST:event_positionToAddTexteItemStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JComboBox positionToAddTexte;
    private javax.swing.JTextField texte;
    // End of variables declaration//GEN-END:variables

    private void actionPerformed() {
        String texte = this.texte.getText();
        PositionUtils.Position pos = ((Couple<PositionUtils.Position>) this.positionToAddTexte.getSelectedItem()).getEnumObject();
        this.parent.setLabelExemple(StringUtils.modifTexteWithAddTexte(FrameContainer.NAMES_FILES_EXEMPLE, texte, pos));

        //StringUtils.modifTexteWithAddTexte(this.parent.getLstFichier(), texte, pos);
    }

    public void updateListeFichier() {
        String texte = AddTextePnl.this.texte.getText();
        PositionUtils.Position pos = ((Couple<PositionUtils.Position>) AddTextePnl.this.positionToAddTexte.getSelectedItem()).getEnumObject();

        StringUtils.modifTexteWithAddTexte(AddTextePnl.this.parent.getLstFichier(), texte, pos);
    }
}
